//
//  ViewController.swift
//  PageNavigator
//
//  Created by chdzq on 08/12/2025.
//  Copyright (c) 2025 chdzq. All rights reserved.
//

import UIKit
import PageNavigator
import SnapKit

class ViewController: UIViewController {
    
    private var page: PageNavigatorController!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.view.backgroundColor = UIColor.red
        
        let vc11 = ContentViewController()
        vc11.title = "测试11"

        let vc12 = ContentViewController()
        vc12.title = "测试12"

        let vc13 = ContentViewController()
        vc13.title = "测试13"

        let vc14 = ContentViewController()
        vc14.title = "测试14"
        
        let segmentDataSource = SegmentItemTitleDataSource(titles: ["测试1", "测试2", "测试3", "测试4"])
        segmentDataSource.itemWidth = 100
        
        let pageContentDataSource = PageContainerDataSource(viewControllers: [vc11, vc12, vc13, vc14])
        segmentDataSource.itemWidth = 100
        
        let indicatorDataSource = SegmentLineIndicatorDataSource()

        let page = PageNavigatorController(segmentDataSource: segmentDataSource, containerDataSource: pageContentDataSource, indicatorDataSource: indicatorDataSource)
        
        self.addChildViewController(page)
        page.beginAppearanceTransition(true, animated: false)
        self.view.addSubview(page.view)
        page.endAppearanceTransition()
        page.didMove(toParentViewController: self)
        
        page.view.snp.makeConstraints { make in
            make.left.equalTo(self.view)
            make.right.equalTo(self.view)
            make.bottom.equalTo(self.view)
            make.top.equalTo(self.view.snp_topMargin)

        }
        
        self.page = page
    }
    
    override func didMove(toParentViewController parent: UIViewController?) {
        super.didMove(toParentViewController: parent)
        print("对象：\(self)method 被执行：\(#function)--\(parent)")
    }

    override func willMove(toParentViewController parent: UIViewController?) {
        super.willMove(toParentViewController: parent)
        print("对象：\(self)method 被执行：\(#function)--\(parent)")
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

